package jzOffer;

public class Num11 {
    public int minArray(int[] numbers) {
        if(numbers.length==1) return numbers[0];
        int low=0;
        int high=numbers.length-1;
        int mid=0;
        while(numbers[low]>=numbers[high]){
            if(high-low==1){
                mid=high;
                break;
            }
            mid=(high-low)/2+low;
            if(numbers[low]==numbers[high] && numbers[mid]==numbers[low])
                return min(numbers,low,high);
            if(numbers[mid]>=numbers[low]){
                low=mid;
            }else if(numbers[mid]<=numbers[high]){
                high=mid;
            }
        }
        return numbers[mid];
    }
    private int min(int[] nums,int low,int high){
        int result=nums[low];
        for(int i=low;i<=high;i++){
            if(nums[i]<result)
                result=nums[i];
        }
        return result;
    }
}
